#正则表达式练习
import re
s = "Do not trouble till trouble troubles you."
r = 't[a-zA-Z]+'
print(re.match(r,s))
print(re.search(r,s))
print(re.findall(r,s))

print()
r = re.compile('t[a-zA-Z]+')
print(r.findall(s))
print(r.sub('-',s))

print()
text = 'alpha. beta....gamma delta'
print(re.split('[\. ]+',text))
print(re.split('[\. ]+',text,maxsplit=2))

print()
pat = '[a-zA-Z]'
print(re.findall(pat,text))
pat = '{me}'
text = 'Dear {me}...'
print(re.sub(pat,'peggy',text))
print(re.sub('a',lambda x:x.group(0).upper(),'aaa abc abde'))
print(re.sub('[a-z]',lambda x:x.group(0).upper(),'aaa abc abde'))
print(re.sub('[a-zA-Z]',lambda x:chr(ord(x.group(0))^32),'aaa aBc abde'))